import  numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.metrics import classification_report
import joblib as  jlb

from  data_format import x_train,y_train,x_test,y_test
from sklearn.naive_bayes import  GaussianNB #导入高斯分布下的朴素贝叶斯

clf = GaussianNB() #实例化
#拟合数据，训练数据fit相当于train
clf.fit(x_train,y_train)

# 保存模型
jlb.dump(clf,'./models/naive_bays.pkl')

pre = jlb.load('./models/naive_bays.pkl')

print("预测的结果是：")
y_pred = pre.predict(x_test)
print(y_pred)
print("属于每个类别的概率分别为：")
print(pre.predict_proba(x_test))
print("属于每个类别的对数转化后的概率分别为：")
print(pre.predict_log_proba(x_test))

print(print(classification_report(y_test, y_pred)))